package com.peaksport.framework.extend.servicecomb;

import javax.annotation.PostConstruct;

import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class PKServiceCombConfiguration {
	
	@PostConstruct
	public void init() {
		//重新配置JSON 序列化
		//swagger对于日期的格式有要求，是ISO8601格式。
		//如果consumer和provider两端都修改为另外的格式并且保持一致的话，应该也能调通，不过接口就不符合swagger标准了
		RestObjectMapperFactory.setConsumerWriterMapper(new PKRestObjectMapper());
		RestObjectMapperFactory.setDefaultRestObjectMapper(new PKRestObjectMapper());
	}
	
	@Bean
	public RestTemplate restTemplate() {
		RestTemplate restTemplate = RestTemplateBuilder.create();
		return restTemplate;
	}
	
	@Bean
	public CseAsyncRestTemplate asynRestTemplate() {
		CseAsyncRestTemplate cseAsyncRestTemplate = new CseAsyncRestTemplate();
		return cseAsyncRestTemplate;
	}
}
